﻿using Business.PubInfo;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControl_ucMhMsgPart : System.Web.UI.UserControl
{
    //默认展示记录条数
    private int nRecordCount = 5;
    public int RecordCount
    {
        set { nRecordCount = value; }
        get { return nRecordCount; }
    }

    //大类
    private string strBigClass = "";
    public string BigClass
    {
        set { strBigClass = value; }
        get { return strBigClass; }
    }

    //小类
    private string strSmallClass = "";
    public string SmallClass
    {
        set { strSmallClass = value; }
        get { return strSmallClass; }
    }

    //where条件
    private string strWhere = "";
    public string WhereCondition
    {
        set { strWhere = value; }
        get { return strWhere; }
    }

    //显示的标题
    private string strTitle = "";
    public string Title
    {
        set { strTitle = value; }
        get { return strTitle; }
    }

    /// <summary>
    /// 隐藏字符的长度
    /// </summary>
    private int nHideLength = 30;
    public int HideLength
    {
        set { nHideLength = value; }
        get { return nHideLength; }
    }

    ///// <summary>
    ///// 限制行显示字符数量
    ///// </summary>
    //private int LineNum = 30;

    //public int LineNum1
    //{
    //    get { return LineNum; }
    //    set { LineNum = value; }
    //}


    /// <summary>
    /// 返回自左边起地len长度的字符
    /// </summary>
    /// <param name="OoStr">字符串对象</param>
    /// <param name="len">自左边起要截取的长度</param>
    /// <returns>返回的处理完的字符串</returns>
    public string Left(string OoStr, int len)
    {
        int Ool = OoStr.Length;
        string OoResult = null;
        if (Ool > len)
        {
            OoResult = OoStr.Substring(0, len) + "...";
        }
        else
        {
            OoResult = OoStr;
        }
        return OoResult;
    }

    /// <summary>
    /// 判断控件的是办事大厅的界面还是信箱公开的界面,默认是信息公开
    /// </summary>
    private string strUrl = "Detail.aspx";

    public string Url
    {
        get { return strUrl; }
        set { strUrl = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {       
        }
    }

    public string GetAllHtml()
    {
        PubInfoManage pimTemp = new PubInfoManage();
        DataTable dtSource = pimTemp.GetPubInfoList(nRecordCount, BigClass, SmallClass, strWhere);

        string strReturn = string.Empty;
        foreach (DataRow drTemp in dtSource.Rows)
        {
            strReturn += string.Format("<p onclick=\"window.open('{0}?lx={1}&art_id={2}');\" style=\"cursor:pointer\"><span style=\" float:right; \">[{4}]</span>{3}</p>", Url, drTemp["lx"], drTemp["id"], Left(drTemp["bt"].ToString(), HideLength), Convert.ToDateTime(drTemp["tjrq"]).ToString("yyyy-MM-dd"));
        }
        return strReturn;
    }
}